package com.wyhgl.onedaycalendar;

import android.app.Activity;
import android.widget.Toast;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;

public class FlutterToNativeUtil implements  MethodChannel.MethodCallHandler{
    public static String CHANNEL = "com.one/plugin";

    static MethodChannel channel;

    private Activity activity;

    private FlutterToNativeUtil(Activity activity) {
        this.activity = activity;
    }
    public static void registerWith(PluginRegistry.Registrar registrar) {
        channel = new MethodChannel(registrar.messenger(), CHANNEL);
        FlutterToNativeUtil instance = new FlutterToNativeUtil(registrar.activity());
        //setMethodCallHandler在此通道上接收方法调用的回调
        channel.setMethodCallHandler(instance);
    }

    @Override
    public void onMethodCall(MethodCall call, MethodChannel.Result result) {
        //通过MethodCall可以获取参数和方法名，然后再寻找对应的平台业务，本案例做了2个跳转的业务
        //接收来自flutter的指令oneAct
        if (call.method.equals("test")) {
            Toast.makeText(activity.getApplicationContext(), "test",Toast.LENGTH_SHORT).show();
        }
        else {
            result.notImplemented();
        }
    }
}
